{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "119fbd7c",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "from sklearn.preprocessing import StandardScaler\n",
    "from sklearn.linear_model import LinearRegression"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "c87aeca7",
   "metadata": {},
   "outputs": [],
   "source": [
    "data = np.loadtxt('../data/USA_Housing.csv',delimiter=',',dtype=str)\n",
    "data = data[1:].astype(float)\n",
    "data = np.random.permutation(data)\n",
    "\n",
    "ratio = 0.8\n",
    "split = int(len(data)*ratio)\n",
    "train = data[:split]\n",
    "test = data[split:]\n",
    "\n",
    "scaler = StandardScaler()\n",
    "scaler.fit(train)\n",
    "train = scaler.transform(train)\n",
    "test = scaler.transform(test)\n",
    "\n",
    "x_train, x_test = train[:,:-1], test[:,:-1]\n",
    "y_train, y_test = train[:,-1], test[:, -1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "63d43328",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(1000,)"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "lin = LinearRegression()\n",
    "lin.fit(x_train, y_train)\n",
    "y_pred = lin.predict(x_test)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "e7d5fcd1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.2844883480267019"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "rmse_loss = np.sqrt(np.square(y_pred.reshape(-1,1) - y_test.reshape(-1,1)).mean())\n",
    "rmse_loss"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "younger",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.23"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
